<template>
  <div>
    <el-table v-loading="props.tableObj.loading" :data="props.tableObj.list" style="width: 100%">
      <el-table-column
        v-for="item in props.tableObj.head.filter(v => !v.slot)" :key="item.key"
        :prop="item.key" :label="item.title" :align="item.align" :min-width="item.minWidth" :fixed="item.fixed" 
        show-overflow-tooltip
      />
      <el-table-column
        v-for="item in props.tableObj.head.filter(v => v.slot)" :key="item.key"
        :label="item.title" :width="item.minWidth" :align="item.center" :fixed="item.fixed"
        show-overflow-tooltip
      >
        <slot :name="item.slot" v-bind="item"></slot>
      </el-table-column>
      <slot></slot>
    </el-table>
    <div class="f ac xe pt15">
      <el-pagination 
        :hide-on-single-page="false"
        background layout="prev, pager, next"
        v-model:current-page="props.tableObj.currentPage"
        :page-size="props.tableObj.pageSize" 
        :total="props.tableObj.totalCount" 
        @change="changePageAndSize"
      />
    </div>
  </div>
</template>
<script setup>
/**
 *表格渲染引擎
  <TableRender :tableObj="tableObj" @setTableObj="e => tableObj = e" @changeTable="e => getList(e)">
    <template #action="row">
      <el-button size="small" type="danger">
        删除{{row.title}}
      </el-button>
    </template>
  </TableRender>
==================数据=====================================
const tableObj = ref({
  head: [
    {title: '患者姓名',key: 'name',minWidth: 100,align:'center'},
    {title: '手机号',key: 'phone', minWidth: 140,align:'center'},
    {title: '身份证号',key: '_idNumber',minWidth: 140,align:'center'},
    {title: '短信内容',key: 'messageContent', minWidth: 100, align:'center'},
    {title: '发送时间',key: 'sendTime',minWidth: 100,align:'center'},
    {title: '发送状态',key: '_sendStatus',minWidth: 100,align:'center'},
    {title: '操作',slot: 'action',minWidth: 100,align: 'center', fixed: 'right'}
  ], // 表头
  list: [
    {name:'张三', phone: '18888179152', _idNumber:'32128114514524854',messageContent:'asdasdasd', sendTime:'2024-05-11',_sendStatus:'已发送'}
  ], // 数据
  currentPage:1, //  当前页码
  pageSize:10, // 每页多少条
  totalCount:0, // 总数
  loading: false, // 表格是否正在loading
})
*/
import { ref } from "vue"
const props = defineProps({
  tableObj: {type: Object, default: () => ({}) },
})
const emit = defineEmits(['setTableObj', 'changeTable'])
/*************************************** */
/**************data********************* */
/*************************************** */

/*************************************** */
/**************function***************** */
/*************************************** */
function changePageAndSize(e){
  const tableObj = { ...props.tableObj, currentPage: e }
  emit('setTableObj', tableObj)
  emit('changeTable', {currentPage: e, pageSize: 10})
}
</script>
<style scoped></style>